package top.healthylife.mapper;

import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.*;
import top.healthylife.domain.Permission;
import top.healthylife.entity.PageResult;

import java.util.List;
import java.util.Set;

public interface PermissionMapper {
    @Select("select p.* from t_permission p,t_role_permission rp where p.id =rp" +
            ".permission_id and rp.role_id =#{id}")
    Set<Permission> findByRoleId(Integer id);

    Page<Permission> selectByCondition(@Param("value") String queryString);

    @Insert("insert into t_permission values (null,#{name},#{keyword},#{description})")
    void add(Permission permission);

    /**
     * 根据权限id查询 是否有角色已经配置该权限
     * @param id
     * @return
     */
    @Select("select count(*) from t_role_permission where permission_id =#{id}")
    long selectCountByPermissionId(Integer id);

    @Delete("delete from t_permission where id = #{id}")
    void deleteById(Integer id);


    void updateById(Permission permission);

    @Select("select * from t_permission")
    List<Permission> findAll();

    @Select("select * from t_permission where id=#{id}")
    Permission findById(Integer id);
}
